/**
 * Filename: GetContactUser.java
 *
 * @author Firefly
 * @contact postfirefly@163.com
 * @time 2016/3/9 1:12
 */
package com.github.postsanf.yinian.utils;

import android.content.Context;
import android.database.Cursor;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.text.TextUtils;

import com.github.postsanf.yinian.bean.YNContactUser;

import java.util.ArrayList;
import java.util.List;

public class GetContactUser {
    public static List<YNContactUser> lists = new ArrayList<YNContactUser>();

    public static String GetContactUser(Context context) {
        //清空已存的列表
        lists.clear();
        Cursor cursor = context.getContentResolver().query(Phone.CONTENT_URI, null, null, null, null);
        if (cursor != null) {
            int uid = 0;
            while (cursor.moveToNext()) {
                String phoneNumber = cursor.getString(cursor.getColumnIndex(Phone.NUMBER));
                if (TextUtils.isEmpty(phoneNumber))
                    continue;
                String phoneName = cursor.getString(cursor.getColumnIndex(Phone.DISPLAY_NAME));
                YNContactUser phoneInfo = new YNContactUser(uid, phoneName, phoneNumber);
                lists.add(phoneInfo);
                uid++;
            }
            cursor.close();
        }
        return null;
    }

}